package com.example.hello.POJO;

import com.example.hello.views.tracks.Tracks;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class TrackPOJO extends POJO {

    public static final String UNASSIGNED = "_unassigned";

    private String organization;
    private List<String> assignments = new LinkedList<>();
    private List<String> badges = new ArrayList<>();

    public TrackPOJO() {
    }

    public TrackPOJO(String name) {
        this(name, UNASSIGNED);
    }

    public TrackPOJO(String name, String organization) {
        this.name = name;
        this.organization = organization;
    }

    public String getOrganization() {
        return organization;
    }

    public void setOrganization(String organization) {
        this.organization = organization;
    }

    public List<String> getAssignments() {
        return assignments;
    }

    public void setAssignments(List<String> assignments) {
        this.assignments = assignments;
    }

    public void addAssignment(String assignment) {
        if (!assignments.contains(assignment)) assignments.add(assignment);
    }

    public boolean removeAssignment(String assignment) {
        return assignments.remove(assignment);
    }

    public boolean hasAssignment(String assignment) {
        return assignments.contains(assignment);
    }

    public List<String> getBadges() {
        return badges;
    }

    public void setBadges(List<String> badges) {
        this.badges = badges;
    }

    public void addBadge(String badge) {
        if (!badges.contains(badge)) badges.add(badge);
    }

    public boolean removeBadge(String badge) {
        return badges.remove(badge);
    }

    public boolean hasBadge(String badge) {
        return badges.contains(badge);
    }

    public String toString() {
        String str = "Track:\n";

        str += "    _id: " + _id + "\n";
        str += "    name: " + name + "\n";
        str += "    organization: " + organization + "\n";
        str += "    assignments: " + Arrays.toString(assignments.toArray()) + "\n";
        str += "    badges: " + Arrays.toString(badges.toArray());

        return str;
    }

    public boolean create() {
        return create(Tracks.NAME, this);
    }

    public boolean update() {
        return update(Tracks.NAME + "/" + name, this);
    }

}